package com.example.security.mapper;

import com.example.security.entity.SysRole;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SysRoleMapper {

    @Select("SELECT * FROM sys_role")
    List<SysRole> selectAll();

    @Select("SELECT * FROM sys_role WHERE id = #{id}")
    SysRole selectById(Long id);

    @Select("SELECT * FROM sys_role WHERE role_code = #{roleCode}")
    SysRole selectByCode(String roleCode);

    @Insert("INSERT INTO sys_role(role_name, role_code, description, status) " +
            "VALUES(#{roleName}, #{roleCode}, #{description}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(SysRole role);

    @Update("UPDATE sys_role SET role_name=#{roleName}, role_code=#{roleCode}, " +
            "description=#{description}, status=#{status} WHERE id=#{id}")
    void update(SysRole role);

    @Delete("DELETE FROM sys_role WHERE id = #{id}")
    void deleteById(Long id);
} 